#' get citation of the given titles
#' 
#' 
#' 
#' 
#' @examples
#' 
#' titles=get_reftitles("my online lib.txt")
#' titles=unique(titles)
#' re=get_citation(titles)
#' 

get_citation=function(titles,slptime=10){
  require(RCurl)
  require(XML)
  nt=length(titles)
  prehttp="http://scholar.glgoo.org/scholar?hl=en&q="
  endhttp="&btnG=&lr="
  Ncitation=numeric()
  for(i in 1:nt){
    title=gsub("([ ])","+",titles[i])
    url=paste(prehttp,title,endhttp,sep="")
    txt=getURL(url)
    Ncitation[i]=as.numeric(strsplit(strsplit(txt,"Cited by ")[[1]][2],"<")[[1]][1])
    print(paste(titles[i],Ncitation[i]))
    
    Sys.sleep(slptime)
  }
  return(Ncitation)
}

#help function to read title from exported file from endnote 
get_reftitles=function(filename){
  info=readLines(filename)
  titles=vector()
  j=1
  for(i in 1:length(info)){
    if(substr(info[i],1,5)=="Title"){
      #print(i)
      nw=try(nchar(info[i]))
      if(class(nw)!="try-error"){
        titles[j]=substr(info[i],8,nchar(info[i]))
        j=j+1
      }
    }
  }
  return(titles)
}
